package bb.lanxing.model.database;

import android.os.Parcel;
import android.os.Parcelable;
import bb.lanxing.util.JsonUtil;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class ProPerms extends LitePalTableBase implements Parcelable {
    public static final String MESSAGE_ATTR_LEVEL_UPGRADE_CONTENT = "benefit";

    public static final Parcelable.Creator<ProPerms> CREATOR = new Parcelable.Creator<ProPerms>() {
        @Override
        public ProPerms createFromParcel(Parcel parcel) {
            return new ProPerms(parcel);
        }

        @Override
        public ProPerms[] newArray(int i) {
            return new ProPerms[i];
        }
    };

    private List<String> benefit;
    private int benefitCan;
    private String benefitJson;

    private MapsBean maps;
    private long mapsId;
    private int monthBuy;
    private String name;

    private Perms perms;
    private long permsId;

    private List<String> permsZh;
    private String permsZhJson;
    private long timeEnd;
    private String timeEndVisual;
    private long timeStart;

    @Override
    public int describeContents() {
        return 0;
    }

    public ProPerms() {
    }

    public ProPerms(JSONObject jSONObject) {
        setName(JsonUtil.getStringValue("name", jSONObject));
        setTimeStart(JsonUtil.getLongValue("time_start", jSONObject));
        setTimeEnd(JsonUtil.getLongValue("time_end", jSONObject));
        setTimeEndVisual(JsonUtil.getStringValue("time_end_visual", jSONObject));
        setBenefitCan(JsonUtil.getIntegerValue("benefit_can", jSONObject));
        setMonthBuy(JsonUtil.getIntegerValue("month_buy", jSONObject));
        JSONObject objectValue = JsonUtil.getObjectValue("perms", jSONObject);
        if (objectValue != null) {
            Perms perms = new Perms(objectValue);
            Perms.deleteAll(Perms.class);
            perms.save();
            setPerms(perms);
            setPermsId(perms.getId());
        }
        JSONObject objectValue2 = JsonUtil.getObjectValue("maps", jSONObject);
        if (objectValue2 != null) {
            MapsBean mapsBean = new MapsBean(objectValue2);
            MapsBean.deleteAll(MapsBean.class);
            mapsBean.save();
            setMaps(mapsBean);
            setMapsId(mapsBean.getId());
        }
        setBenefitJson(JsonUtil.getStringValue(MESSAGE_ATTR_LEVEL_UPGRADE_CONTENT, jSONObject));
        setPermsZhJson(JsonUtil.getStringValue("perms_zh", jSONObject));
    }

    public static ProPerms getProPerms() {
        try {
            ProPerms p = findFirst(ProPerms.class);
            return p;

//            return (ProPerms) Select.from(ProPerms.class).first();
        } catch (Exception unused) {
            return null;
        }
    }

    protected ProPerms(Parcel parcel) {
        this.name = parcel.readString();
        this.timeStart = parcel.readLong();
        this.timeEnd = parcel.readLong();
        this.timeEndVisual = parcel.readString();
        this.benefitCan = parcel.readInt();
        this.monthBuy = parcel.readInt();
        this.perms = (Perms) parcel.readParcelable(Perms.class.getClassLoader());
        this.maps = (MapsBean) parcel.readParcelable(MapsBean.class.getClassLoader());
        this.benefit = parcel.createStringArrayList();
        this.permsZh = parcel.createStringArrayList();
        this.permsZhJson = parcel.readString();
        this.permsId = parcel.readLong();
        this.mapsId = parcel.readLong();
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(this.name);
        parcel.writeLong(this.timeStart);
        parcel.writeLong(this.timeEnd);
        parcel.writeString(this.timeEndVisual);
        parcel.writeInt(this.benefitCan);
        parcel.writeInt(this.monthBuy);
        parcel.writeLong(this.permsId);
        parcel.writeLong(this.mapsId);
        parcel.writeParcelable(this.perms, i);
        parcel.writeParcelable(this.maps, i);
        parcel.writeStringList(this.benefit);
        parcel.writeStringList(this.permsZh);
        parcel.writeString(this.permsZhJson);
    }

    public String getName() {
        return this.name;
    }

    public void setName(String str) {
        this.name = str;
    }

    public long getTimeStart() {
        return this.timeStart;
    }

    public void setTimeStart(long j) {
        this.timeStart = j;
    }

    public long getTimeEnd() {
        return this.timeEnd;
    }

    public void setTimeEnd(long j) {
        this.timeEnd = j;
    }

    public String getTimeEndVisual() {
        return this.timeEndVisual;
    }

    public void setTimeEndVisual(String str) {
        this.timeEndVisual = str;
    }

    public int getBenefitCan() {
        return this.benefitCan;
    }

    public void setBenefitCan(int i) {
        this.benefitCan = i;
    }

    public int getMonthBuy() {
        return this.monthBuy;
    }

    public void setMonthBuy(int i) {
        this.monthBuy = i;
    }

    public Perms getPerms() {
        if (this.perms == null) {
            long j = this.permsId;
            if (j > 0) {
                this.perms = Perms.getById(j);
            }
        }
        return this.perms;
    }

    public void setPerms(Perms perms) {
        this.perms = perms;
    }

    public List<String> getBenefit() {
        if (this.benefit == null && this.benefitJson != null) {
            try {
                ArrayList arrayList = new ArrayList();
                JSONArray jSONArray = new JSONArray(this.benefitJson);
                for (int i = 0; i < jSONArray.length(); i++) {
                    arrayList.add(jSONArray.get(i).toString());
                }
                return arrayList;
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return this.benefit;
    }

    public void setBenefit(List<String> list) {
        this.benefit = list;
    }

    public String getBenefitJson() {
        return this.benefitJson;
    }

    public void setBenefitJson(String str) {
        this.benefitJson = str;
    }

    public List<String> getPermsZh() {
        if (this.permsZh == null && this.permsZhJson != null) {
            try {
                ArrayList arrayList = new ArrayList();
                JSONArray jSONArray = new JSONArray(this.permsZhJson);
                for (int i = 0; i < jSONArray.length(); i++) {
                    arrayList.add(jSONArray.get(i).toString());
                }
                return arrayList;
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return this.permsZh;
    }

    public void setPermsZh(List<String> list) {
        this.permsZh = list;
    }

    public String getPermsZhJson() {
        return this.permsZhJson;
    }

    public void setPermsZhJson(String str) {
        this.permsZhJson = str;
    }

    public long getPermsId() {
        return this.permsId;
    }

    public void setPermsId(long j) {
        this.permsId = j;
    }

    public MapsBean getMaps() {
        if (this.maps == null) {
            long j = this.mapsId;
            if (j > 0) {
                this.maps = MapsBean.getById(j);
            }
        }
        return this.maps;
    }

    public void setMaps(MapsBean mapsBean) {
        this.maps = mapsBean;
    }

    public long getMapsId() {
        return this.mapsId;
    }

    public void setMapsId(long j) {
        this.mapsId = j;
    }
}
